public class test01 {
        List<List<Integer>> res;
        List<Integer> list;
        boolean[] used;
        public List<List<Integer>> permute(int[] nums) {
            res = new ArrayList<>();
            list = new ArrayList<>();
            used = new boolean[nums.length];
            backTracking(nums);
            return res;
        }
        private void backTracking(int[] nums){
            if(list.size()==nums.length){
                res.add(new ArrayList(list));
                return;
            }
            for(int i = 0;i<nums.length;i++){
                if(used[i]){
                    continue;
                }
                used[i] = true;
                list.add(nums[i]);
                backTracking(nums);
                used[i] = false;
                list.removeLast();
            }
        }
}
